package com.atguigu.demo.customer.controller;


import com.atguigu.demo.customer.bean.Customer;
import com.atguigu.demo.customer.service.CustomerService;
import com.atguigu.demo.customer.service.impl.CustomerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    CustomerService customerService;

    ///customer/sayHello?name=zhang3&age=88
    @RequestMapping("/sayHello")
    public  String  sayHello(@RequestParam(value = "name",required = false) String name , @RequestParam(value = "age",required = false) Integer age ){
        return "hello world123 , name="+name +" , age="+age;
    }

    @GetMapping("/info/{id}")
    public String getCustomer(@PathVariable("id") String id){
        return  " customer id ="+id;
    }

    @PostMapping("/info")
    public String saveCustomer(@RequestBody Customer customer){
        System.out.println("customer = " + customer);
        System.out.println("customer = " + customer);
        System.out.println("customer = " + customer);
        System.out.println("customer = " + customer);


        customerService.saveCustomer(customer);

        return customer.toString();
    }


    @GetMapping("/infos")
    public String getCustomer(   Customer customer){
        System.out.println("customer = " + customer);
        System.out.println("customer = " + customer);
        System.out.println("customer = " + customer);
        System.out.println("customer = " + 10/0);


        return customer.toString();
    }
}
